package com.zhiyi.coco.controller;

import com.zhiyi.coco.entity.FoodInfo;
import com.zhiyi.coco.service.FoodInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(value = "FoodInfoController", description = "饮品信息编辑")
@RestController
@RequestMapping("/foodinfo")
@Log4j
public class FoodInfoController {
    @Autowired
    private FoodInfoService service;

    @ApiOperation("获取foodinfo表中的数据")
    @ResponseBody
    @RequestMapping("/getAll/{fId}")
    private List<FoodInfo> getAll(@PathVariable Integer fId) {
        List<FoodInfo> list = service.getAll(fId);
        if (list == null) {
            return null;
        }
        return list;
    }

    @ApiOperation("获取Material表中的数据")
    @ResponseBody
    @RequestMapping("/getAllNoParam")
    public List<FoodInfo> getAllNoParam() {
        List<FoodInfo> list = service.getAllNoParam();
        if(list==null){
            return null;
        }
        return list;
    }

    /**
     * @return 根据饮品编号获取饮品信息
     */
    @ApiOperation("根据饮品编号获取饮品信息")
    @ResponseBody
    @RequestMapping("/getInfoById/{id}")
    public FoodInfo getInfoById(@PathVariable Integer id) {
        FoodInfo food = service.getInfoById(id);
        log.info(food.getTypeId());
        if(food==null){
            return null;
        }
        return food;
    }

    /**
     * @return 根据饮品编号删除用户信息
     */
    @ApiOperation("根据饮品编号删除用户信息")
    @ResponseBody
    @RequestMapping("/deleteInfoById/{id}")
    public boolean deleteInfoById(@PathVariable Integer id) {
        Integer i = service.deleteInfoById(id);
        if (i > 0) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * @return 根据id删除饮品图片路径
     */
    @ApiOperation("根据用户编号修改饮品信息")
    @ResponseBody
    @RequestMapping("/updateimgbyid/{id}")
    public Boolean updateimgbyid(@PathVariable Integer id) {
        Integer i = service.updateimgbyid(id);
        if (i > 0) {
            return true;
        }
        return false;
    }

    /**
     * @return 修改饮品信息
     */
    @ApiOperation("根据用户编号修改饮品信息")
    @ResponseBody
    @RequestMapping("/updateInfo")
    public Boolean insertInfo(FoodInfo foodInfo) {
        Integer i = service.updateByPrimaryKey(foodInfo);
        log.info(foodInfo);
        if (i > 0) {
            return true;
        }
        return false;
    }

    /**
     * @return 添加饮品信息
     */
    @ApiOperation("根据用户编号修改饮品信息")
    @ResponseBody
    @RequestMapping("/insert")
    public Boolean insert(FoodInfo foodInfo) {
        Integer i = service.insert(foodInfo);
        log.info(foodInfo);
        if (i > 0) {
            return true;
        }
        return false;
    }

//    selectFid
    /**
     * @return 根据饮品编号获取饮品编号
     */
    @ApiOperation("根据饮品编号获取饮品编号")
    @ResponseBody
    @RequestMapping("/selectFid/{yinpinname}")
    public FoodInfo selectFid(@PathVariable String yinpinname) {
        FoodInfo id =service.selectFid(yinpinname);
        if(id==null){
            return null;
        }
        return id;
    }

//    updateFid
    /**
     * @return 添加饮品信息
     */
    @ApiOperation("根据用户编号修改饮品信息")
    @ResponseBody
    @RequestMapping("/updateFid/{yinpinname}/{re}")
    public Boolean updateFid(@PathVariable String yinpinname,@PathVariable Integer re) {
        Integer i = service.updateFid(yinpinname,re);
        if (i > 0) {
            return true;
        }
        return false;
    }
}
